package com.movisol.messengercommunicator.data;

public class Contact {
	
	private String ContactId;
	private String Name;
	private String Email;
	
	public Contact()
	{
		super();
		ContactId = null;
		Name = null;
	}

	public String getContactId() {
		return ContactId;
	}

	public void setContactId(String contactId) {
		ContactId = contactId;
	}

	public String getName() {
		return Name;
	}
	
	public String getCalculatedName()
	{
		if(Name != null && !Name.trim().equals(""))
		{
			return Name.length() > 20 ? Name.substring(0, 20).concat("...") : Name;
		}
		else
		{
			if(Email != null&& !Email.trim().equals(""))
			{
				String subEmail = Email.substring(0, Email.indexOf("@")); 
				return subEmail.length() > 20 ? subEmail.substring(0, 20).concat("...") : subEmail;
			}
		}
		return "NoName";
	}

	public void setName(String name) {
		Name = name;
	}

	public String getEmail() {
		return Email;
	}

	public void setEmail(String email) {
		Email = email;
	}

	@Override
	public String toString() {
		return "Contact [ContactId=" + ContactId + ", Name=" + Name + ", Email=" + Email + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((ContactId == null) ? 0 : ContactId.hashCode());
		result = prime * result + ((Email == null) ? 0 : Email.hashCode());
		result = prime * result + ((Name == null) ? 0 : Name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Contact other = (Contact) obj;
		if (ContactId == null) {
			if (other.ContactId != null)
				return false;
		} else if (!ContactId.equals(other.ContactId))
			return false;
		if (Email == null) {
			if (other.Email != null)
				return false;
		} else if (!Email.equals(other.Email))
			return false;
		if (Name == null) {
			if (other.Name != null)
				return false;
		} else if (!Name.equals(other.Name))
			return false;
		return true;
	}


	
	

}
